Hi
I have a sheet named DB which contains many named ranges, such as Earth_DB, Concrete_DB, Blocks_DB etc.... I have a UserForm to add info to each range, using CheckBox buttons as the code shows below. However I Can't seem to properly do it because once I click the Add button the info is not sent to the specific range, but is sent randomly Any Help would be great
CODE:
Option Explicit
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("DB")
Dim Rng1, Rng2, Rng3, Rng4 As Range
Set Rng1 = ws.Range("EarthWorks_DB")
Set Rng2 = ws.Range("Concrete_DB")
Set Rng3 = ws.Range("Stones_DB")
Set Rng4 = ws.Range("Blocks_DB")
'find first empty row in database
With CheckBox1 = True
iRow = Rng1.Cells(Rows.Count).End(xlUp).Offset(1, 0).Row
'copy the data to the database
Rng1.Cells(iRow, 1).Value = Me.TxtName.Value
Rng1.Cells(iRow, 2).Value = Me.TxtQty.Value
Rng1.Cells(iRow, 3).Value = Me.TxtMaterial.Value
Rng1.Cells(iRow, 4).Value = Me.TxtLabor.Value
Rng1.Cells(iRow, 5).Value = Me.TxtSC.Value
Rng1.Cells(iRow, 6).Value = Me.TxtEquip.Value
End With
With CheckBox2 = True
iRow = Rng2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'copy the data to the database
Rng2.Cells(iRow, 1).Value = Me.TxtName.Value
Rng2.Cells(iRow, 2).Value = Me.TxtQty.Value
Rng2.Cells(iRow, 3).Value = Me.TxtMaterial.Value
Rng2.Cells(iRow, 4).Value = Me.TxtLabor.Value
Rng2.Cells(iRow, 5).Value = Me.TxtSC.Value
Rng2.Cells(iRow, 6).Value = Me.TxtEquip.Value
End With
can this be done any simpler?
IJQ
I have a sheet named DB which contains many named ranges, such as Earth_DB, Concrete_DB, Blocks_DB etc.... I have a UserForm to add info to each range, using CheckBox buttons as the code shows below. However I Can't seem to properly do it because once I click the Add button the info is not sent to the specific range, but is sent randomly Any Help would be great
CODE:
Option Explicit
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("DB")
Dim Rng1, Rng2, Rng3, Rng4 As Range
Set Rng1 = ws.Range("EarthWorks_DB")
Set Rng2 = ws.Range("Concrete_DB")
Set Rng3 = ws.Range("Stones_DB")
Set Rng4 = ws.Range("Blocks_DB")
'find first empty row in database
With CheckBox1 = True
iRow = Rng1.Cells(Rows.Count).End(xlUp).Offset(1, 0).Row
'copy the data to the database
Rng1.Cells(iRow, 1).Value = Me.TxtName.Value
Rng1.Cells(iRow, 2).Value = Me.TxtQty.Value
Rng1.Cells(iRow, 3).Value = Me.TxtMaterial.Value
Rng1.Cells(iRow, 4).Value = Me.TxtLabor.Value
Rng1.Cells(iRow, 5).Value = Me.TxtSC.Value
Rng1.Cells(iRow, 6).Value = Me.TxtEquip.Value
End With
With CheckBox2 = True
iRow = Rng2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'copy the data to the database
Rng2.Cells(iRow, 1).Value = Me.TxtName.Value
Rng2.Cells(iRow, 2).Value = Me.TxtQty.Value
Rng2.Cells(iRow, 3).Value = Me.TxtMaterial.Value
Rng2.Cells(iRow, 4).Value = Me.TxtLabor.Value
Rng2.Cells(iRow, 5).Value = Me.TxtSC.Value
Rng2.Cells(iRow, 6).Value = Me.TxtEquip.Value
End With
can this be done any simpler?
IJQ