adding data to rows in different columns

jaycee

Active Member
Joined
Jul 22, 2009
Messages
323
Hi,

My worksheet does varying things which I have managed to get to work well.

My only issue is getting the correct data into the correct amount of rows, I have managed to get the first 2 columns correct but then populating another column with data from a userform and adding the date is what I need to do.

The first 2 columns are copied from sheet 1 with the amount required from a userrform, I need the same amount added to this data in sheet 2.

Code:
Private Sub CmdEnter_Click()
    Dim arr()   As Variant
    Dim wks     As Worksheet
    Dim x       As Long
    
    Application.ScreenUpdating = False
    
    'Set up input box
    On Error Resume Next
    x = FrmCards.TxtNo.Value
    
    'Copy Rows
    If x > 0 Then
        With Sheets("Sheet1").Cells(2, 1).Resize(x, 2)
            arr = .Value
            .EntireRow.Delete shift:=xlUp
        End With
    Else
        MsgBox "Invalid input!" & vbCrLf & vblcrf & "Please try again", vbExclamation, "Invalid Input"
        Exit Sub
    End If
    Set wks = Sheets("Sheet2")
    On Error GoTo 0
            
    'Paste rows into sheet 2
    If wks Is Nothing Then
        Set wks = Sheets.Add(after:=Sheets(Sheets.Count))
        With wks
            .Name = "Sheet2"
            .Cells(1, 1).Resize(, 2).Value = Sheets("Sheet1").Cells(1, 1).Resize(, 2).Value
        End With
    End If
    With wks
[SIZE=3][COLOR=#0000FF]        .Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr[/COLOR][/SIZE]
       [SIZE=4][FONT=arial black][COLOR=#FF0000] .Cells(Rows.Count, 3).End(xlUp).Offset(1).Value = FrmCards.TxtRemedy.Value
        .Cells(Rows.Count, 4).End(xlUp).Offset(1).Value = Now()[/COLOR][/FONT][/SIZE]
        End With
    'Paste rows into sheet 3
    Sheets("sheet3").Select
    Set wks = Sheets("Sheet3")
        With wks
           .Cells(1, 1).Resize(, 2).Value = Sheets("Sheet1").Cells(1, 1).Resize(, 2).Value
        End With
    wks.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr
    Erase arr
    
    'Copy Sheet 3 to new workbook & delete data in sheet 3
    New_Sheet
    Application.ScreenUpdating = True
End With
End Sub

It is the 2 rows in red that I have an issue with, I need them to be the same size as the row in Blue, but not sure how this can be done
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try
Code:
.Cells(Rows.Count, 3).End(xlUp).Offset(1).Resize(x).Value = FrmCards.TxtRemedy.Value
.Cells(Rows.Count, 9).End(xlUp).Offset(1).Resize(x).Value = Now()
 
Upvote 0
Your welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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