INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

copying rows from one table to another

copying rows from one table to another

(OP)

Can someone please tell me why this code works...

CODE

If Sheets("Sales Datasheet").Cells(i, "C").Value = "672144" Then
     Sheets("Sales Datasheet").Cells(i, "E").EntireRow.Copy Destination:=Sheets("Office View").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If 

But this one doesn't.

CODE

If Sheets("Sales Datasheet").Cells(i, "C").Value = byagentcb.value Then
     Sheets("Sales Datasheet").Cells(i, "E").EntireRow.Copy Destination:=Sheets("Office View").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If 

And if I debug.print byagentcb.value, it is "672144". Column C is a Number Value and I've even tried declaring byagentcb as Integer, Long, and Variant.


RE: copying rows from one table to another

What is baygentcb? Test its value from code (Msgbox or Debug.Print), test
Sheets("Sales Datasheet").Cells(i, "C").Value = byagentcb.value 
for
True/False 
.

combo

RE: copying rows from one table to another

(OP)
When I do debug.print byagentcb.value, I get '672144'. But when I do debug.print Sheets("Sales Datasheet").cells(i,"C").value = byagentcb.value, I get False, and when I hard code "672144" instead of byagentcb.value... I get the results I'm looking for.

RE: copying rows from one table to another

"672144" <> 672144

A string is not equal to a number all containing the same digits in the same order, if that indeed is the case.

"byagentcb.value" implies that byagentcb is an Object of some kind and not a normal variable. How is byagentcb 1) declared, 2) Set and 3) assigned a value?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: copying rows from one table to another

(OP)

The combobox has 3 columns:

B C D from the Worksheet "Agent Datasheet"
|licnumber|lastname|firstname|

and bound to licnumber. The B column in the table is formatted as text. The data is entered into the table on another form with the following code:

CODE

With ws          'worksheet "Agent Datasheet"
        .Cells(lRow, 1).Value = Me.TRECLICNUMBERbox.Value + 123     'loginpasscode
        .Cells(lRow, 2).Value = Me.TRECLICNUMBERbox.Value           'TREC License Number
        .Cells(lRow, 3).Value = Me.LASTNAMEbox.Value                'Last Name
        .Cells(lRow, 4).Value = Me.FIRSTNAMEbox.Value               'First Name
        .....more to this.....
    End With 

The textbox on the data entry from is formatted as Text

Then on the worksheet I have the dropdown "byagentcb" which gets assigned the |licnumber|lastname|firstname| on Worksheet.Activate() using this code:


CODE

Private Sub Worksheet_Activate()
    Dim lastrow
    lastrow = Sheets("Agent Datasheet").Range("A" & Rows.Count).End(xlUp).Row
    Dim myArray As Variant
    myArray = Worksheets("Agent Datasheet").Range("B3:D" & lastrow)
    byagentcb.List = myArray
End Sub 

It's using this dropdown that I use to pull the data from one sheet to another temp sheet using this code. This was the initial code I used, which didn't work... then I also tried to use CStr(byagentcb.value), but that didn't work either.

CODE

Dim i, lastrow
    lastrow = Sheets("Sales Datasheet").Range("A" & Rows.Count).End(xlUp).Row
    Sheets("Office View").Range("A3:AB1000").ClearContents
    For i = 2 To lastrow
        If Sheets("Sales Datasheet").Cells(i, "C").Value = byagentcb.Value Then
            Sheets("Sales Datasheet").Cells(i, "E").EntireRow.Copy Destination:=Sheets("Office View").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End If
    Next i 

RE: copying rows from one table to another

(OP)
Sorry.... I still don't know why it didn't work the way I wrote it originally because it all seemed to be text... but it's working now by using a variable instead of the dropdown value.

Added/changed the highlighted

CODE

Dim i, lastrow
    Dim byagent As String
    lastrow = Sheets("Sales Datasheet").Range("A" & Rows.Count).End(xlUp).Row
    Sheets("Office View").Range("A3:AB1000").ClearContents
    byagent = CStr(BYAGENTcb.Value)
    For i = 2 To lastrow
        If Sheets("Sales Datasheet").Cells(i, "C").Value = byagent Then
            Sheets("Sales Datasheet").Cells(i, "E").EntireRow.Copy Destination:=Sheets("Office View").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End If
    Next i 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close