Vb/vba error
-
Hi Miguel - I used your following code from one of your earlier interactions: Sub CopyCells() Dim rngData As Range, rngDest As Long Dim i, j As Integer Set rngData = Sheets("Invoice").Range("A16:g35") Set rngDest = Sheets("InvData").Range("A1").End(xlDown).Offset(1, 0) For i = 1 To rngData.Rows.Count If rngData.Cells(i, 1) <> "" Then rngDest.Offset(j, 0).Value = Sheets("Invoice").Range("b8").Value rngDest.Offset(j, 1).Value = Sheets("Invoice").Range("b10").Value rngDest.Offset(j, 2).Value = rngData.Cells(i, 1).Value rngDest.Offset(j, 3).Value = rngData.Cells(i, 2).Value rngDest.Offset(j, 4).Value = rngData.Cells(i, 3).Value rngDest.Offset(j, 5).Value = rngData.Cells(i, 4).Value rngDest.Offset(j, 6).Value = rngData.Cells(i, 6).Value rngDest.Offset(j, 7).Value = Sheets("Invoice").Range("b9").Text j = j + 1 End If Next End Sub However, everytime I ran it, I kept getting an error - compile error, object required. Am I not doing something right regarding the code? Please note that I am a newbie.
-
Answer:
Just a couple of things. rngDest should be declared as a Range, not as Long, and the code was looking for at least two rows with headers on the InvData sheet. A fix could be something like: Sub CopyCells() Dim rngData As Range, rngDest As Range Dim i, j As Integer Set rngData = Sheets("Invoice").Range("A16:g35") Set rngDest = Sheets("InvData").Range("A1") j = rngDest.CurrentRegion.Rows.Count ... This will keep the functionality of appending rows, and avoid the error related to use the End property here.
Miningco.com Visit the source
Related Q & A:
- How to Convert Code from VB to C++?Best solution by Stack Overflow
- How to solve the “Your search cannot be completed because of a service error” error in Search Center?Best solution by SharePoint
- How I can find string in excel with vba?Best solution by Stack Overflow
- How to save from DatagridView to Database VB.NET?Best solution by Stack Overflow
- How to fix error printer Canon PIXMA iP1000 error msg The waste in absorber is full. Ink counter i reset?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.