Need VBA stript for column selection

  • Thread starter Thread starter Chris D
  • Start date Start date
C

Chris D

I have a variable named " number", which can range from 1 to 10( entered via
inputbox
Now I need a VBA script which, depending on the value of " number", selects
a series of columns. Example: if "number" =1 than columns T:Z to be selected,
if "number"= 2 than columns U: Z to be selected, if 3 than V:Z to be selected
VBA code I have so far:
Sub Calculationstart()

number = InputBox("How Many Days in this Report??")
Range("U2").Select
ActiveCell.FormulaR1C1 = Daynumber

'Columns("T:Z").Select
' ActiveWindow.SmallScroll Down:=-63

Can anyone help me, maybe function IF can be used but I have not done this
before.

thanks
 
maybe this will gt you started:

Sub test()
Dim result As Long

result = Application.InputBox("Enter Number of Days", "Days in Report")

Select Case result
Case 1
Columns("T:Z").Select
Case 2
Columns("U:Z").Select
Case 3
Columns("V:Z").Select
Case Else
MsgBox "please enter a valied number"
End Select

End Sub
 
sorry about the spelling errors<g>

--


Gary


Gary Keramidas said:
maybe this will gt you started:

Sub test()
Dim result As Long

result = Application.InputBox("Enter Number of Days", "Days in Report")

Select Case result
Case 1
Columns("T:Z").Select
Case 2
Columns("U:Z").Select
Case 3
Columns("V:Z").Select
Case Else
MsgBox "please enter a valied number"
End Select

End Sub
 
try
Sub selectcolums()
mc = InputBox("enter number") + 19
Range(Cells(1, mc), Cells(1, "z")).EntireColumn.Select
End Sub
 
I had thought about posting code something like that, but I didn't because I
wasn't sure what was supposed to happen when mc equaled 8, 9 or 10.

Rick
 
Thanks guys, this works.
Amazing what VBA can do, and will save us a lot of time. Now we only have to
press a button( once I worked it all out) instead of copy-pasting for days to
get a summary of dayreports.

Thanks!

Chris
 
Back
Top