Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Help with VBA Script

I have a 28 column input spreadsheet which I need to convert to 6 columns for
Database input. I have to sheets in the workbook, "Input" and "Output" Please
help with the VBA below, I am asked to debug from Inpt.Range

Sub rearrange_data()
Application.ScreenUpdating = False
For i = 2 To InputBox("How many lines?")
For c = 1 To 24
Inpt.Range(Cells(i, 1), Cells(i, 3)).Copy
Output.Cells(((i - 1) * 24) - 24 + c, 1).PasteSpecial xlValues
Inpt.Cells(i, c + 4).Copy
Output.Cells(((i - 1) * 24) - 24 + c, 6).PasteSpecial xlValues
If c <= 12 Then
Output.Cells(((i - 1) * 24) - 24 + c, 5) = "2009"
Else
Output.Cells(((i - 1) * 24) - 24 + c, 5) = "2010"
End If

Select Case c
Case 1
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "01"
Case 2
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "02"
Case 3
Case 24
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "12"
End Select
Next c

Next i
Output.Activate

Application.CutCopyMode = False
Range("A1").Select
Selection.EntireRow.Insert
Range("A1").Select
ActiveCell.FormulaR1C1 = "Username"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Project"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Proj name"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Month"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Year"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Hours"
Range("A1").Select
Selection.AutoFilter
Range("F1").Select
Selection.AutoFilter Field:=6, Criteria1:="="
Range("F2:F65000").Select
Selection.EntireRow.Delete
Selection.AutoFilter Field:=6

Application.ScreenUpdating = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Help with VBA Script

Hi

Is Inpt and Output supposed to be variables refering to the sheets or ?

If the first is the case, I think you need to declare the variables in the
macro.

Try this before the loop :

Dim Inpt as Worksheet
Dim Output as Worksheet
Set Inpt=Worksheets("Input")
Set Output=Worksheets("Output")

Hopes this helps.

---
Per

"Chase" skrev i meddelelsen
...
I have a 28 column input spreadsheet which I need to convert to 6 columns
for
Database input. I have to sheets in the workbook, "Input" and "Output"
Please
help with the VBA below, I am asked to debug from Inpt.Range

Sub rearrange_data()
Application.ScreenUpdating = False
For i = 2 To InputBox("How many lines?")
For c = 1 To 24
Inpt.Range(Cells(i, 1), Cells(i, 3)).Copy
Output.Cells(((i - 1) * 24) - 24 + c, 1).PasteSpecial xlValues
Inpt.Cells(i, c + 4).Copy
Output.Cells(((i - 1) * 24) - 24 + c, 6).PasteSpecial xlValues
If c <= 12 Then
Output.Cells(((i - 1) * 24) - 24 + c, 5) = "2009"
Else
Output.Cells(((i - 1) * 24) - 24 + c, 5) = "2010"
End If

Select Case c
Case 1
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "01"
Case 2
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "02"
Case 3
Case 24
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "12"
End Select
Next c

Next i
Output.Activate

Application.CutCopyMode = False
Range("A1").Select
Selection.EntireRow.Insert
Range("A1").Select
ActiveCell.FormulaR1C1 = "Username"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Project"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Proj name"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Month"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Year"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Hours"
Range("A1").Select
Selection.AutoFilter
Range("F1").Select
Selection.AutoFilter Field:=6, Criteria1:="="
Range("F2:F65000").Select
Selection.EntireRow.Delete
Selection.AutoFilter Field:=6

Application.ScreenUpdating = True
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Help with VBA Script

Hi Per

I did as you suggested but the debug is still going to the row strating
Inpt.Range


"Per Jessen" wrote:

Hi

Is Inpt and Output supposed to be variables refering to the sheets or ?

If the first is the case, I think you need to declare the variables in the
macro.

Try this before the loop :

Dim Inpt as Worksheet
Dim Output as Worksheet
Set Inpt=Worksheets("Input")
Set Output=Worksheets("Output")

Hopes this helps.

---
Per

"Chase" skrev i meddelelsen
...
I have a 28 column input spreadsheet which I need to convert to 6 columns
for
Database input. I have to sheets in the workbook, "Input" and "Output"
Please
help with the VBA below, I am asked to debug from Inpt.Range

Sub rearrange_data()
Application.ScreenUpdating = False
For i = 2 To InputBox("How many lines?")
For c = 1 To 24
Inpt.Range(Cells(i, 1), Cells(i, 3)).Copy
Output.Cells(((i - 1) * 24) - 24 + c, 1).PasteSpecial xlValues
Inpt.Cells(i, c + 4).Copy
Output.Cells(((i - 1) * 24) - 24 + c, 6).PasteSpecial xlValues
If c <= 12 Then
Output.Cells(((i - 1) * 24) - 24 + c, 5) = "2009"
Else
Output.Cells(((i - 1) * 24) - 24 + c, 5) = "2010"
End If

Select Case c
Case 1
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "01"
Case 2
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "02"
Case 3
Case 24
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "12"
End Select
Next c

Next i
Output.Activate

Application.CutCopyMode = False
Range("A1").Select
Selection.EntireRow.Insert
Range("A1").Select
ActiveCell.FormulaR1C1 = "Username"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Project"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Proj name"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Month"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Year"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Hours"
Range("A1").Select
Selection.AutoFilter
Range("F1").Select
Selection.AutoFilter Field:=6, Criteria1:="="
Range("F2:F65000").Select
Selection.EntireRow.Delete
Selection.AutoFilter Field:=6

Application.ScreenUpdating = True
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Help with VBA Script

Hi Per
Thanks for your help. I re-wrote the whole script in a new file and got the
process to work.
Regards
Chase

"Per Jessen" wrote:

Hi

You need to set the sheet reference for the cells too:

Inpt.Range(Inpt.Cells(i, 1), Inpt.Cells(i, 3)).Copy

Regards,
Per

"Chase" skrev i meddelelsen
...
Hi Per

I did as you suggested but the debug is still going to the row strating
Inpt.Range


"Per Jessen" wrote:

Hi

Is Inpt and Output supposed to be variables refering to the sheets or ?

If the first is the case, I think you need to declare the variables in
the
macro.

Try this before the loop :

Dim Inpt as Worksheet
Dim Output as Worksheet
Set Inpt=Worksheets("Input")
Set Output=Worksheets("Output")

Hopes this helps.

---
Per

"Chase" skrev i meddelelsen
...
I have a 28 column input spreadsheet which I need to convert to 6
columns
for
Database input. I have to sheets in the workbook, "Input" and "Output"
Please
help with the VBA below, I am asked to debug from Inpt.Range

Sub rearrange_data()
Application.ScreenUpdating = False
For i = 2 To InputBox("How many lines?")
For c = 1 To 24
Inpt.Range(Cells(i, 1), Cells(i, 3)).Copy
Output.Cells(((i - 1) * 24) - 24 + c, 1).PasteSpecial xlValues
Inpt.Cells(i, c + 4).Copy
Output.Cells(((i - 1) * 24) - 24 + c, 6).PasteSpecial xlValues
If c <= 12 Then
Output.Cells(((i - 1) * 24) - 24 + c, 5) = "2009"
Else
Output.Cells(((i - 1) * 24) - 24 + c, 5) = "2010"
End If

Select Case c
Case 1
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "01"
Case 2
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "02"
Case 3
Case 24
Output.Cells(((i - 1) * 24) - 24 + c, 4) = "12"
End Select
Next c

Next i
Output.Activate

Application.CutCopyMode = False
Range("A1").Select
Selection.EntireRow.Insert
Range("A1").Select
ActiveCell.FormulaR1C1 = "Username"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Project"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Proj name"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Month"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Year"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Hours"
Range("A1").Select
Selection.AutoFilter
Range("F1").Select
Selection.AutoFilter Field:=6, Criteria1:="="
Range("F2:F65000").Select
Selection.EntireRow.Delete
Selection.AutoFilter Field:=6

Application.ScreenUpdating = True
End Sub





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with vba script lariveesl New Users to Excel 5 June 6th 09 08:53 AM
VBA script Gor_yee Excel Discussion (Misc queries) 1 April 28th 09 10:43 AM
Can any help with a little script Danny Boy via OfficeKB.com Excel Programming 6 January 29th 06 11:47 AM
VB script help..please !! Anthony Excel Worksheet Functions 2 June 5th 05 03:26 PM
Excel 2000/XP script to Excel97 script hat Excel Programming 3 March 2nd 04 03:56 PM


All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"