Simple String Question

jnewlin

New Member
Joined
Aug 2, 2007
Messages
18
Easy question here. I am trying to reference a string from one worksheet and display it on anther worksheet.

Code is below. It works if I use

Name1 = Range("B2").Value

for example, but I want it to use the user input row labeled LSG below.

Name1 = Range("B" & LSG).Value

does not work. Why? I'm guessing it's a simple keyword I'm missing.

Sub SG1()
Dim LSG As Integer
Dim Name1 As String

Sheets("Size").Select
LSG = Range("J2").Value
Name1 = Range("B" & LSG)
Sheets("Sheet1").Select
Range("B13").Value = Name1
...

End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
It's not necessary to do all that selecting. LSG should be dimmed as Long as the number of rows available exceeds the amount allowed by the Integer data type.

Assuming J2 on sheet Size holds a valid row number:

Code:
Sub SG1()
Dim LSG As Long
LSG = Sheets("Size").Range("J2")
Sheets("Sheet1").Range("B13") = Sheets("Size").Range("B" & LSG)
End Sub
 
Upvote 0
i always thought it had to be a string in order for it to work in Range()

dim LSG as string

???

just assuming didn't run any tests or anything
 
Upvote 0
Hi

No need to select things - usually unnecessary but unfortunately slow. Do you get an error? If so what is it, and where does it occur?
 
Upvote 0
QuietRiot

No it doesn't need to be a string.:)

And really shouldn't be a string.:)
 
Upvote 0
Never a need to select?

So there is never a need to use a line to select a sheet to move throughout the workbook? I can always reference within the same line of code the worksheet I'm using?

When I make combobox selections I see the screen flashing alot. Many values are getting repopulated, but is it because of this select command that the screen flashes and it takes a few seconds to populate all my data?
 
Upvote 0
Well I wouldn't say there's never a need, that really depends on what you are doing.

But I think the code you posted doesn't need selecting.:)
 
Upvote 0

Forum statistics

Threads
1,214,324
Messages
6,118,890
Members
448,854
Latest member
Eduard_Stoo

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