'I want to conditionally copy a range
I want to conditionally copy a range from a table that have 10 rows and 3 columns
I'm using this:
Sub COPIAR()
Worksheets("01").Range("T3:AA13").Copy
End Sub
I want to copy the rows, and if the first column have no value, the VBA will skip the entire row
I tried this, but now im getting erron on this section "Dim drg As Range: Set drg = dfcell.Resize(dr, cCount)"
Option Explicit
Sub CopyCriteriaRows()
Const sName As String = "GERAL"
Const srgAddress As String = "B3:I13"
Const dName As String = "GERAL"
Const dfCellAddress As String = "B4"
Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
Dim sws As Worksheet: Set sws = wb.Worksheets(sName)
Dim srg As Range: Set srg = sws.Range(srgAddress)
Dim cCount As Long: cCount = srg.Columns.Count
Dim Data As Variant: Data = srg.Value
Dim sr As Long
Dim dr As Long
Dim c As Long
For sr = 1 To UBound(Data, 1)
If Len(CStr(Data(sr, 1))) > 0 Then
dr = dr + 1
For c = 1 To cCount
Data(dr, c) = Data(sr, c)
Next c
End If
Next sr
Dim dws As Worksheet: Set dws = wb.Worksheets(dName)
Dim dfcell As Range: Set dfcell = dws.Range(dfCellAddress)
Dim drg As Range: Set drg = dfcell.Resize(dr, cCount)
drg.Value = Data
End Sub
Heres prints from my worksheet(starting from the on the first row bellow CC - B3:I13, note that i have hidden columns
I forgot a detail, my table has formulas, maybe this is preventing me from copying to the clipboard
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|