check date to see if code can be run

alan myers

Board Regular
Joined
Oct 31, 2017
Messages
119
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub CopyTranspose()

Dim rowPay As Long, colPay As Long, rowComb As Long
Dim nCarrier As Long, irowComb As Long, icolPay As Long
Dim rngCopy As Range, rngPaste As Range
Dim wb As Workbook
Dim wsPayroll As Worksheet, wsCombine As Worksheet

Set wb = ActiveWorkbook
Set wsPayroll = wb.Sheets("Payroll")
Set wsCombine = wb.Sheets("Combine")

Application.ScreenUpdating = False

' Get next empty row
rowPay = wsPayroll.Cells(Rows.Count, "C").End(xlUp).Offset(1).Row
' Initital column in wsPayroll
icolPay = 3
' Initital row on wsCombine
irowComb = 3

For nCarrier = 0 To 194
    colPay = icolPay + (nCarrier * 11)
    rowComb = irowComb + (nCarrier * 12)
    Set rngCopy = wsCombine.Range("B" & rowComb).Resize(10, 1)
    Set rngPaste = wsPayroll.Cells(rowPay, colPay)
    rngPaste.Resize(1, rngCopy.Rows.Count) = Application.WorksheetFunction.Transpose(rngCopy.Value)
Next

End Sub

https://www.mediafire.com/file/bbx1vzl6ccuepzf/Payroll+v3.xlsm/file my file

before this code is run I need to check the payroll tab to find the next empty row then check that rows date in column a if it matches today's date then run the code else end

like to and this code to the start of my code
 
Last edited by a moderator:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug. My signature block below has more details. I have added them for you this time. ?
 
Upvote 0
before this code is run I need to check the payroll tab to find the next empty row then check that rows date in column a if it matches today's date then run the code else end

Try adding these two red lines where shown

Rich (BB code):
Sub CopyTranspose()

  Dim rowPay As Long, colPay As Long, rowComb As Long
  Dim nCarrier As Long, irowComb As Long, icolPay As Long
  Dim rngCopy As Range, rngPaste As Range
  Dim wb As Workbook
  Dim wsPayroll As Worksheet, wsCombine As Worksheet
  
  Set wb = ActiveWorkbook
  Set wsPayroll = wb.Sheets("Payroll")
  Set wsCombine = wb.Sheets("Combine")
  
  If wsPayroll.Range("A" & wsPayroll.Range("BHE" & Rows.Count).End(xlUp).Row + 1).Value = Date Then
    Application.ScreenUpdating = False
    
    ' Get next empty row
    rowPay = wsPayroll.Cells(Rows.Count, "C").End(xlUp).Offset(1).Row
    ' Initital column in wsPayroll
    icolPay = 3
    ' Initital row on wsCombine
    irowComb = 3
    
    For nCarrier = 0 To 194
        colPay = icolPay + (nCarrier * 11)
        rowComb = irowComb + (nCarrier * 12)
        Set rngCopy = wsCombine.Range("B" & rowComb).Resize(10, 1)
        Set rngPaste = wsPayroll.Cells(rowPay, colPay)
        rngPaste.Resize(1, rngCopy.Rows.Count) = Application.WorksheetFunction.Transpose(rngCopy.Value)
    Next
  End If
End Sub
 
Upvote 0
Solution
Try adding these two red lines where shown

Rich (BB code):
Sub CopyTranspose()

  Dim rowPay As Long, colPay As Long, rowComb As Long
  Dim nCarrier As Long, irowComb As Long, icolPay As Long
  Dim rngCopy As Range, rngPaste As Range
  Dim wb As Workbook
  Dim wsPayroll As Worksheet, wsCombine As Worksheet
 
  Set wb = ActiveWorkbook
  Set wsPayroll = wb.Sheets("Payroll")
  Set wsCombine = wb.Sheets("Combine")
 
  If wsPayroll.Range("A" & wsPayroll.Range("BHE" & Rows.Count).End(xlUp).Row + 1).Value = Date Then
    Application.ScreenUpdating = False
   
    ' Get next empty row
    rowPay = wsPayroll.Cells(Rows.Count, "C").End(xlUp).Offset(1).Row
    ' Initital column in wsPayroll
    icolPay = 3
    ' Initital row on wsCombine
    irowComb = 3
   
    For nCarrier = 0 To 194
        colPay = icolPay + (nCarrier * 11)
        rowComb = irowComb + (nCarrier * 12)
        Set rngCopy = wsCombine.Range("B" & rowComb).Resize(10, 1)
        Set rngPaste = wsPayroll.Cells(rowPay, colPay)
        rngPaste.Resize(1, rngCopy.Rows.Count) = Application.WorksheetFunction.Transpose(rngCopy.Value)
    Next
  End If
End Sub
thanks work fine just what i needed you guys are great
 
Upvote 0
You're welcome. Thanks for the confirmation. :)
 
Upvote 0

Forum statistics

Threads
1,214,897
Messages
6,122,141
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top