Good morning. How are you all? Hope you all are doing great.
I'm looking for some urgent assistance in VBA codes. I have to make one VBA programme .xlsm. I've two files. One is my main file and other one is my lookup file.
I want that when I run program, it ask me about my required file and I tell about file (b/c file changes every month). After it receives given file it will apply 2 formulas, gross amount and net amount (after finding their required columns for formula) and day part lookup from lookup file. All these columns will be added at the end of the last available empty column. Below are the formulas:
gross amount = (unit rate/60) * duration
net amount = (gross amount/duration) * 30
Day part lookup from lookup file
Note: Column position isn't fixed and column heading names are fixed.
I've tried by myself to write a code, few lines are there and need assistance for a complete code according with my requirement. Below are few lines and 2 files are also attached.
I hope you understand what I mean. My english isn't good. If you have any problem then you may ask me about that. Thanks in advance for helping me.
I'm looking for some urgent assistance in VBA codes. I have to make one VBA programme .xlsm. I've two files. One is my main file and other one is my lookup file.
I want that when I run program, it ask me about my required file and I tell about file (b/c file changes every month). After it receives given file it will apply 2 formulas, gross amount and net amount (after finding their required columns for formula) and day part lookup from lookup file. All these columns will be added at the end of the last available empty column. Below are the formulas:
gross amount = (unit rate/60) * duration
net amount = (gross amount/duration) * 30
Day part lookup from lookup file
Note: Column position isn't fixed and column heading names are fixed.
I've tried by myself to write a code, few lines are there and need assistance for a complete code according with my requirement. Below are few lines and 2 files are also attached.
VBA Code:
Private Sub Daypartandgrossandnetamount()
'my Variables
Dim ws1 As Worksheet, ws2 As Worksheet
Dim lastrow As Long
Dim lastcolumn As Long
'Asking for opening required file
If ws1 Is Nothing Then
ChDrive ThisWorkbook.Path: ChDir ThisWorkbook.Path
fn = Application.GetOpenFilename("ExcelBooks,*.xlsx", , "Select [Required File.xlsx]")
If fn = "False" Then Exit Sub
Set ws1 = Workbooks.Open(fn, False).Sheets("Sheet1")
End If
With ws1
'Defined my last row & column
lastrow = .Range("A" & .Rows.Count).End(xlUp).Row
lastcolumn = Cells(1, Columns.Count).End(xlToLeft).Column
End With
End Sub
I hope you understand what I mean. My english isn't good. If you have any problem then you may ask me about that. Thanks in advance for helping me.
Raw file.xlsx | |||
---|---|---|---|
K | |||
11 | |||
Sheet1 |
Lookups.xlsx | |||
---|---|---|---|
I | |||
11 | |||
Lookups |
Last edited by a moderator: