First Post!
I'm brand new to VBA and what I know is from reading part of a book, so please bear with me.
I have a workbook that is modifed and saved on a daily basis, with an exerpt from my code below:
Windows("Yields_Bulk_CY10Daily_12.17.2012.xls").Activate
I'd like to do the following: Insert a variable into the path that would dictate the date portion. i.e. x = xx.xx.xxxx I understand that I can simply open it every day and dictate the day that way, but eventually this will be handed off and I don't want a user in the editor playing with the code.
Ultimately, I'll creat a pop-up that will provide the user the entry point, where "x" will be defined.
Can anyone provide some input on how this can be accomplished?
If needed, the entire string of code is below:
Sub SAPYieldDataImport()
Msg = "Import Yield Data from SAP?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
MsgBox "Data Not Imported. No Changes Made."
Else
Windows("Worksheet in ALVXXL01 (1)").Activate
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Windows("Yields_Bulk_CY10Daily_12172012.xls").Activate
Sheets("data drop").Select
Range("A2").Select
ActiveSheet.Paste
Calculate
Range("R2").Select
Application.CutCopyMode = False
Range("A1:R3000").Sort Key1:=Range("R2"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
End If
Sheets("Main").Select
Range("A1").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
Dim NRows As Long
NRows = Range("AQ2").Value
ActiveCell.Resize(NRows, 1).EntireRow.Insert
Sheets("Data Drop").Select
Range("A2:Q2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Main").Activate
Range("A2").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveSheet.Paste
Calculate
Range("S2").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Offset(-1, 0).Select
Range(ActiveCell, ActiveCell.Offset(0, 23)).Select
Selection.Copy
For x = 1 To Worksheets("Data Drop").Range("X2")
Range(ActiveCell.Offset(x, 0), ActiveCell.Offset(0, 23)).Select
ActiveSheet.Paste
Next x
Calculate
End Sub
I'm brand new to VBA and what I know is from reading part of a book, so please bear with me.
I have a workbook that is modifed and saved on a daily basis, with an exerpt from my code below:
Windows("Yields_Bulk_CY10Daily_12.17.2012.xls").Activate
I'd like to do the following: Insert a variable into the path that would dictate the date portion. i.e. x = xx.xx.xxxx I understand that I can simply open it every day and dictate the day that way, but eventually this will be handed off and I don't want a user in the editor playing with the code.
Ultimately, I'll creat a pop-up that will provide the user the entry point, where "x" will be defined.
Can anyone provide some input on how this can be accomplished?
If needed, the entire string of code is below:
Sub SAPYieldDataImport()
Msg = "Import Yield Data from SAP?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
MsgBox "Data Not Imported. No Changes Made."
Else
Windows("Worksheet in ALVXXL01 (1)").Activate
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Windows("Yields_Bulk_CY10Daily_12172012.xls").Activate
Sheets("data drop").Select
Range("A2").Select
ActiveSheet.Paste
Calculate
Range("R2").Select
Application.CutCopyMode = False
Range("A1:R3000").Sort Key1:=Range("R2"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
End If
Sheets("Main").Select
Range("A1").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
Dim NRows As Long
NRows = Range("AQ2").Value
ActiveCell.Resize(NRows, 1).EntireRow.Insert
Sheets("Data Drop").Select
Range("A2:Q2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Main").Activate
Range("A2").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveSheet.Paste
Calculate
Range("S2").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Offset(-1, 0).Select
Range(ActiveCell, ActiveCell.Offset(0, 23)).Select
Selection.Copy
For x = 1 To Worksheets("Data Drop").Range("X2")
Range(ActiveCell.Offset(x, 0), ActiveCell.Offset(0, 23)).Select
ActiveSheet.Paste
Next x
Calculate
End Sub