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
 

Some videos you may like

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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
 

QuietRiot

Well-known Member
Joined
May 18, 2007
Messages
1,077
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
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

QuietRiot

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

And really shouldn't be a string.:)
 

jnewlin

New Member
Joined
Aug 2, 2007
Messages
18
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?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
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.:)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,809
Messages
5,598,202
Members
414,218
Latest member
speedbit

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
Top