Cell Range instead active cell

nidhipatel

Board Regular
Joined
Feb 11, 2017
Messages
52
my cell range is A2:C2. i need cell range A2:C2 use in blow code instead active cell
how it is correct

Cells(Rows.Count, 2).End(xlUp).End(xlToLeft).Offset(0, i - 1).Select

Range(ActiveCell, ActiveCell.End(xlUp).Offset(1, 0)).Value = Controls("TextBox" & i).Text
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Can I assume:
1. You have three textbox's on your Userform and you want the value in Textbox1 entered into Range("A2")
and the value in Textbox2 entered into Range("B2") and the value in Textbox3 entered into Range("C2")

Is that what your wanting to do?
 
Upvote 0
If the answer to my question is yes.
Try this:
Code:
Private Sub CommandButton2_Click()
'Modified 4-20-18 12:40 AM EDT
Dim i As Long
    For i = 1 To 3
        Cells(2, i).Value = Controls("Textbox" & i).Value
    Next
End Sub
 
Upvote 0
sir i explain project my userform contain 2 macro. every time enter data data will be add in worksheet "DATA" in last blank rows every time.

Macro 1 is "FillDocCenterAmount"
Macro 2 is "FillDateSenderFrom"


i need Result show as below after 2 macro runs



BARODA DELHI
BARODA BHARUCH
BARODA SURAT
BARODA SAVLI
BARODA NAVSARI

<colgroup><col style="mso-width-source:userset;mso-width-alt:3108;width:64pt" width="85"> <col style="mso-width-source:userset;mso-width-alt:4352;width:89pt" width="119"> <col style="mso-width-source:userset;mso-width-alt:3218;width:66pt" width="88"> <col style="mso-width-source:userset;mso-width-alt:3328;width:68pt" width="91"> <col style="mso-width-source:userset;mso-width-alt:3949;width:81pt" width="108"> <col style="mso-width-source:userset;mso-width-alt:3108;width:64pt" width="85"> </colgroup><tbody>
[TD="class: xl64, width: 85"] DATE
[/TD]
[TD="class: xl64, width: 119"] SENDER
[/TD]
[TD="class: xl64, width: 88"]FROM[/TD]
[TD="class: xl64, width: 91"]DOC NO[/TD]
[TD="class: xl64, width: 108"] CENTER
[/TD]
[TD="class: xl64, width: 85"]AMOUNT[/TD]

[TD="class: xl63, align: right"]03/11/2018
[/TD]
[TD="class: xl63"] KALPESH
[/TD]

[TD="align: right"]132455456
[/TD]

[TD="align: right"]50[/TD]

[TD="class: xl63, align: right"]03/11/2018
[/TD]
[TD="class: xl63"] KALPESH
[/TD]

[TD="align: right"]132455457
[/TD]

[TD="align: right"]30[/TD]

[TD="class: xl63, align: right"]03/11/2018
[/TD]
[TD="class: xl63"] KALPESH
[/TD]

[TD="align: right"]132455458[/TD]

[TD="align: right"]30
[/TD]

[TD="class: xl63, align: right"]03/11/2018[/TD]
[TD="class: xl63"] KALPESH
[/TD]

[TD="align: right"]132455459[/TD]

[TD="align: right"]30
[/TD]

[TD="class: xl63, align: right"]03/11/2018[/TD]
[TD="class: xl63"] KALPESH
[/TD]

[TD="align: right"]132455460[/TD]

[TD="align: right"]30[/TD]

</tbody>




Sub FillDocCenterAmount()

Dim i As Integer



For i = 4 To 8
If Controls("TextBox" & i) <> "" Then
If Worksheets("DATA").Range("D1").Offset(1, 0).Value = "" Then
Worksheets("DATA").Range("D1").Offset(1, 0).Value = Controls("TextBox" & i).Text
Else
Worksheets("DATA").Range("D1").End(xlDown).Offset(1, 0).Value = Controls("TextBox" & i).Text
End If
End If
Next i

For i = 9 To 13
If Controls("TextBox" & i) <> "" Then
If Worksheets("DATA").Range("E1").Offset(1, 0).Value = "" Then
Worksheets("DATA").Range("E1").Offset(1, 0).Value = Controls("TextBox" & i).Text
Else
Worksheets("DATA").Range("E1").End(xlDown).Offset(1, 0).Value = Controls("TextBox" & i).Text
End If
End If
Next i

For i = 14 To 18
If Controls("TextBox" & i) <> "" Then
If Worksheets("DATA").Range("F1").Offset(1, 0).Value = "" Then
Worksheets("DATA").Range("F1").Offset(1, 0).Value = Controls("TextBox" & i).Text
Else
Worksheets("DATA").Range("F1").End(xlDown).Offset(1, 0).Value = Controls("TextBox" & i).Text
End If
End If
Next i
End Sub





Sub FillDateSenderFrom()

For i = 1 To 3
If Controls("TextBox" & i) <> "" Then
If i = 1 Then
Worksheets("DATA").Activate
Cells(Rows.Count, 2).End(xlUp).End(xlToLeft).Offset(0, i - 1).Select
Range(ActiveCell, ActiveCell.End(xlUp).Offset(1, 0)).Value = Controls("TextBox" & i).Text
Else
Cells(Rows.Count, 2).End(xlUp).End(xlToLeft).Offset(0, 1).Select
Range(ActiveCell, ActiveCell.End(xlUp).Offset(1, 0)).Value = Controls("TextBox" & i).Text
End If
End If
Next i



End Sub
 
Upvote 0
So you have shown me all this code you have but I see no question.
Are you saying you wrote all this code but it does not work.


Then tell me what your wanting to do.

You have not said in words what your wanting to do.
 
Upvote 0
my problem is

when delete any cell value in "DATA" worksheet and run macro data wili be over right.
because second macro find last blank cell and add data. i need find last blank rows and add data.
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,603
Members
452,658
Latest member
GStorm

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