Topic:excel macro problems Remainpoint:0
   
PostTime:12/16/2008 1:54:43 PM FloorTop
Lv is 1
Avatar
Level:
1
Professional point:
62
Experience:
17
Thread:
308
Post:
944
Total online time:
17M
Joined date:
4/28/2007 11:22:00 PM
Last Visit:
12/16/2008 11:38:28 PM
Status:
Offline
I'm trying to create a macro that will add a new line at a certain point on the next sheet of a workbook, and then pastes information into that new line, when sb presses a button.

Until now I only ever did macros by recording them, and then assigning them to a commandbutton, and had no problems with that;
Now I keep gettting an error message telling me there is a bug. And that assistant which pops up marks the <i>Rows("38:38").Select</i> as wrong- but as i have no knowledge of VB I don't really see what's wrong with it.

Private Sub CommandButton1_Click()
Sheets("Lizenzmeldungen").Select
Rows("38:38").Select
Selection.Insert Shift:=xlDown
Sheets("Dateneingabe").Select
End Sub

Also, it'd be great to have something like "find the line where it says X, and put the new row right below that"; if you got any suggestions for that please let me know.

Thanks!
 
     
   
Gender PostTime:12/16/2008 2:43:12 PM Point:0 | Floor# 1
Lv is 1
portrait
Level:
1
Professional point:
6
Experience:
1
Thread:
288
Post:
960
Total online time:
1M
Joined date:
4/28/2007 10:58:00 PM
Last Visit:
12/17/2008 12:46:54 AM
Status:
Offline
Quote:
Originally Posted by PyRoMaNIN
How can i point the "X" to a cell? I tried putting "cell(1,1)" into the place where x is now, but it doesn't seem to like this.

"X", as anything between two quotation marks, is a string. You have to replace it with the cell's content, like
Code:
Selection.Find(What:=Cells(1,1).Value, After:=ActiveCell, LookIn:=xlValues, LookAt _ :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=False).Activate

Better, if you use a variable, ant put it into the Find procedure.
Code:
Dim SeekWhat as StringSeekWhat = ActiveSheet.Cells(1,1).ValueSelection.Find(What:=SeekWhat, After:=ActiveCell, LookIn:=xlValues, LookAt _ :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=False).Activate


Quote:
Originally Posted by PyRoMaNIN
Or: can you point me to a VB tutorial or FAQ where I can look up these kind of things myself?

Well, no. I, myself, learned practically everything from the built-in help. Another valuable source of knowledge is the code of recorded macros. But surely there are great Excel sites out there...
 
     
   
Gender PostTime:12/16/2008 6:09:08 PM Point:0 | Floor# 2
Lv is 1
portrait
Level:
1
Professional point:
71
Experience:
5
Thread:
316
Post:
950
Total online time:
5M
Joined date:
4/28/2007 10:49:00 PM
Last Visit:
12/16/2008 11:39:24 PM
Status:
Offline
No need to apologize, it's my pleasure to help you. Really.
Doubly so, if I can beat OBP by replying first

You can refer to any cells the following way:
Code:
WorkBooks("wbkname").Sheets("Shtname").Cells(y,x)
where y and x are rowindex and columnindex, respectively.
WorkBooks is optional, by default it is the active workbook (the xls file).
If the cell is on the currently active sheet, you can use
Code:
ActiveSheet.Cells(y,x)

If you want to copy its content, use a variable
Code:
CellContent = Sheets("Sheet1").Cells(y1,x1).ValueSheets("Sheet2").Cells(y2,x2).Value= CellContent

If you want to copy the cells formula, use "Formula" instead of "Value".
You can also omit using variable, and simply transferring the cells content in one step.

So after all this, the macro should be like this:
Code:
Sub neuesProdukt() SourceSheet=ActiveSheet.Name' Cells(6, 3).Select' Selection.Copy SeekWhat = Sheets(SourceSheet).Cells(6, 2).Value Sheets("Lizenzmeldungen").Activate Columns(1).Select Cells(1, 1).Activate Selection.Find(What:=SeekWhat, After:=ActiveCell, LookIn:=xlValues, LookAt _ :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=False).Activate Rows(ActiveCell.Row + 1).Select Selection.Insert Shift:=xlDown Selection.Interior.ColorIndex = xlNone SelectedRow=Selection.Row ActiveSheet.Cells(SelectedRow,1).Value = Sheets(SourceSheet).Cells(6,3).Value' Columns(1).Select' Selection.Paste' Application.CutCopyMode = FalseEnd Sub
I left in the unneccessary lines, and signed them as comments (starting with ' ).
 
     
   
Gender PostTime:12/16/2008 6:35:57 PM Point:0 | Floor# 3
Lv is 2Lv is 2
portrait
Level:
2
Professional point:
1
Experience:
53
Thread:
308
Post:
995
Total online time:
53M
Joined date:
4/28/2007 10:52:00 PM
Last Visit:
12/16/2008 11:36:38 PM
Status:
Offline
Quote:
Originally Posted by OBP
sorry Malacka, I didn't see your post, I was too busy typing (slowly).

No problem, I always fall into the same trap
Only I type more slowly than you, because I have to translate my thoughts first
 
     
   
Gender PostTime:12/16/2008 8:46:45 PM Point:0 | Floor# 4
Lv is 2Lv is 2
portrait
Level:
2
Professional point:
1
Experience:
53
Thread:
308
Post:
995
Total online time:
53M
Joined date:
4/28/2007 10:52:00 PM
Last Visit:
12/16/2008 11:36:38 PM
Status:
Offline
sorry Malacka, I didn't see your post, I was too busy typing (slowly).
 
     
1

Sorry, you are not login, click here to login

 

About us | Advertise | Contact us | Partner | Bug Report|Suggesting box|Donation
Home | Forum | Affiliate program| Remote help | Setting | Search | Document | Help | Download|Message

 

Start new topicAdvanced search