Need VBA stript for column selection

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
 
G

Gary Keramidas

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
 
G

Gary Keramidas

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
 
D

Don Guillett

try
Sub selectcolums()
mc = InputBox("enter number") + 19
Range(Cells(1, mc), Cells(1, "z")).EntireColumn.Select
End Sub
 
R

Rick Rothstein \(MVP - VB\)

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
 
C

Chris D

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top