How do I make my subs not change inputdata in Vba excel

0 votes

When I call a sub and supply a variable, the passed variable is altered after the sub terminates. How can I stop it from doing that?

Debug. print in the example should therefore be 3 rather than 8.

sub main()
  i = 3
  SomeSub i
  debug.print i
end sub

sub SomeSub(j)
  j=j+5
end sub
Feb 5, 2023 in Others by Kithuzzz
• 38,010 points
307 views

1 answer to this question.

0 votes

Use the ByVal keyword to pass on the value

Sub SomeSub(ByVal j As Long)
  j = j + 5
End Sub
answered Feb 5, 2023 by narikkadan
• 63,700 points

Related Questions In Others

0 votes
1 answer

How do I use the Indirect Function in Excel VBA to incorporate the equations in a VBA Macro Function

Try this: Sub Test() Dim str As String: str ...READ MORE

answered Jan 19, 2023 in Others by narikkadan
• 63,700 points
777 views
0 votes
1 answer

How Do I Correct a ByRef Mismatch Error in VBA for Worksheet_Change Sub in Excel?

Len of a string returns what you need. ...READ MORE

answered Apr 1, 2023 in Others by narikkadan
• 63,700 points
1,425 views
0 votes
0 answers

How do I determine the size of my array in C?

How do I determine the size of ...READ MORE

May 1, 2022 in Others by Kichu
• 19,050 points
274 views
0 votes
1 answer

How can I find and replace text in Word using Excel VBA?

Try this code Option Explicit Const wdReplaceAll = 2 Sub ...READ MORE

answered Oct 15, 2022 in Others by narikkadan
• 63,700 points
4,211 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
980 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,330 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
634 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,670 points
854 views
0 votes
1 answer

How do I insert a WebP-image (".jpg") in Excel using VBA?

It's not currently on the list of ...READ MORE

answered Nov 15, 2022 in Others by narikkadan
• 63,700 points
567 views
0 votes
1 answer

How do I run a VBA Sub routine continuously when working in a Workbook and not only when the Workbook is opened?

on Thisworkbook, put: Private Sub Workbook_Open() Call checkPW(True) End Sub Then ...READ MORE

answered Jan 14, 2023 in Others by narikkadan
• 63,700 points
395 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP