Range inside cell reference

Tablecloth98

New Member
Joined
Nov 15, 2023
Messages
16
Office Version
  1. 2021
Platform
  1. Windows
I'm trying to specify a range from L1 to Q where the row value of Q if specified by the value of a cell in another sheet (Let's say Worksheets("Sheet1").Range("N" & i)).

I've defined variable j as an integer and set it to equal Worksheets("Sheet1").Range("N" & i) however, when I try to use the variable j in a cell reference Range("L1:Q" & j) it returns a syntax error.

Does anybody know where I'm going wrong with this?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Could you post a code? It should be something like that:
VBA Code:
Dim j&
Dim rng As Range

j = Worksheets("Sheet1").Range("N" & i)
Set rng = Range("L1:Q" & j)
 
Upvote 0
Solution
Sorry guys I've figured it out (I've been at it for hours 😂) I'd missed a bracket off further along the formula, then it came up with a type mismatch because the cell wasn't formatted as a number. Thank you for your responses though 🙂
 
Upvote 0
@Sektor provided the right solution for the text only question. Therefore, I marked it as the correct answer in order to help future readers.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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