Trying to set two variables as one variable.

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
810
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm counting the number of PU's, which I've set as "PUdonk = 0" then later, "PUdonk = PUdonk + 1"

Code:
    Do Until Cells(ActiveCell.Row, "B").Value = ""        If ActiveCell.Offset(2, 0).Value = "Rail" Then
        PUdonk = PUdonk + 1
        "PU" & PUdonk = ActiveCell.Offset(1, 0).Value
        End If
    Loop

What I'm trying to achieve is the first time it finds "Rail" 2 cells below the active cell, it names the value one cell below the active cell as "PU1" (because 0+1 is 1)

Then when it finds the second value of Rail, it names the next cell "PU2"

And so on

The trouble is the last line "PU" & PUdonk...." is highlighted with the error: "Compile error: Expected: line number of label or statement or end of statement"

Any ideas? In my head, this was very straightforward :')

Ah, after more googling, this can't be done.

Instead I've created a helper row which will be named "PU1" "PU2" etc and I will just reference them in that fashion.
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You cannot use variables in that way.
However you could use an Array to store values you want
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top