Question on pointing to different sheets in VB

insectpugilist

New Member
Joined
Jul 17, 2011
Messages
1
Hi, I'm new to programming with VB though I have some experience with C. Well, I should post my commented code first before I ask.

Code:
Dim dlp, ap, lat, effdia, conversionfactor As Double
Dim count, bodypart As Integer

bodypart = Cells(2, A).Value 'assigns value in excel sheet to variable 
dlp = Cells(4, A).Value
ap = Cells(5, A).Value
lat = Cells(6, A).Value

If lat = 0 And bodypart = 1 Then
    effdia = Math.Round(ap) 'rounds to nearest integer
    Application.Goto ActiveWorkbook.Sheets("head").Cells(effdia, 2)
    'goes to a certain row in "head" (a different sheet)
    conversionfactor = Cells(effdia, 2).Value 'copies value into conversionfactor
    
    ElseIf lat <> 0 And bodypart = 1 Then
    effdia = Math.Round(Math.Sqr(ap * lat)) 'I'm allowed to do this right?
    Application.Goto ActiveWorkbook.Sheets("head").Cells(effdia, 5)
    conversionfactor = Cells(effdia, 5).Value
End If

I got the

Code:
Application.Goto ActiveWorkbook.Sheets("head").Cells(effdia, 2)

from the [microsoft website](http://support.microsoft.com/kb/291308). My question is, do I need to do this every time I want to point to another sheet? Or is there another way to tell the program to refer to another sheet (in the same workbook)?

Am I allowed in VB to use the variable effdia as a number to be used in Cells(effdia, 2)? Basically I want to know if I'm doing it right so far... Thanks.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You shouldn't need to select a cell in order to access its contents. Instead of

Code:
Application.Goto ActiveWorkbook.Sheets("head").Cells(effdia, 2)
    'goes to a certain row in "head" (a different sheet)
conversionfactor = Cells(effdia, 2).Value 'copies value into conversionfactor

try

Code:
conversionfactor = Sheets("head").Cells(effdia, 2).Value 'copies value into conversionfactor
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,283
Members
452,902
Latest member
Knuddeluff

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