|
-
Mar 22nd, 2006, 10:26 PM
#1
Thread Starter
New Member
need help
i totally new to this VB. and also macro in excel.
i need to do basically searching copy and paste.
for example
enter name to active cell then the macro will search for the name and copy all the data.on other sheet then patse to the active sheet
please any body can help me
-
Mar 22nd, 2006, 10:49 PM
#2
Re: need help
Welcome to the Forums.
To start learning VBA easiest way is to record a macro doing the tasks you need. Then stop recording and check out the generated macro code in the VBA IDE (Alt+F11).
Your going to want to look at the .Find method.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 23rd, 2006, 07:02 AM
#3
Thread Starter
New Member
Re: need help
tanks for the head start..
but rite now i`m stuck..
here is my plan..
i`ve stated 1 variable let say name
so i want macro to search the name in other sheet then if found macro will copy all the data beside the name than transfer to previous sheet..
the thing is i donnot know how to move the activecell .. can assign active cell as variable
-
Mar 23rd, 2006, 09:14 AM
#4
Frenzied Member
Re: need help
rexxar:
Is the name on the "other" sheet(s) always in a particular column? Are you moving data from the reference sheet from particular columns to the same columns or to different columns on the active sheet? Are you copying ALL of the data on the row from the reference sheet to the active sheet? What happens if you don't find the selected name on the reference sheet? Please be a little more specific with the format of the data. What you are trying to do is not difficult.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Mar 23rd, 2006, 11:50 AM
#5
Re: need help
Dont use Name as a variable as its a reserved word.
Post your code.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 28th, 2006, 04:19 AM
#6
Thread Starter
New Member
Re: need help
sory man i`ve been away for quite some time..
this is my code
VB Code:
Sub DecideUserInput()
Dim bText As String
Dim bsheet As String
Dim rng As Range
Dim rng2 As Range
Dim i As Integer
Dim y As Integer
Dim r As Long
Dim c, d As Integer
Dim c1 As Integer
Dim c2 As Integer
Dim a As Integer
Dim b As Integer
' here is the INPUTBOX-function :
bText = InputBox("Insert in a text", "This accepts any input")
' here is the INPUTBOX-method :
ActiveCell.FormulaR1C1 = bText
Set rng = Sheet1.UsedRange
'Set rng2 = Sheet1.UsedRange.Rows
'a = Selection.Column.Value ' i tried to extract the location of the active cell so that i can get row and column number
'b = Selection.row.Value
Worksheets("sheet2").Select
Range("b1").Select
' initial state
c = 4 'colloum
i = 1 'row
d = a + 1
c1 = c + 1
c2 = c
Do
For i = 1 To 60
If Sheet2.Cells(i, c).Value = bText Then
Do
For y = c1 To 8
Sheet2.Cells(i, y).Copy
Sheet1.Select
Sheet1.Cells(b, d).Paste
Next y
Loop Until y = 8
Sheet2.Select
Sheet2.Cells(i, c2).Copy
Sheet1.Select
Sheet1.Cells(1, 3).Select
activeselection.Paste
End If
Next i
Loop Until i = 60
End Sub
it`s not pretty because i try and error.. one thing, when i tried to run this code my excel spreadsheet crash..
-
Mar 28th, 2006, 08:34 AM
#7
Frenzied Member
Re: need help
If you really want to learn what goes on in VBA, make the very top line of your module "Option Explicit". Setting this option requires that you, the programmer, must properly define and declare each and every variable. If you don't set this option, VBA will make some assumptions and automatically assign data types to variables if you don't. This can lead to some unusual problems, such as if you misspell a variable name ... VBA will just create and use a new variable with the incorrect spelling!
Also, remember that you can get a lot of helpful code templates by using the Macro Recorder wizard. Just record snippets of operations and look at the code that is produced for 'hints'.
In the above code, I think there is a problem with variables "Sheet1" and "Sheet2". Here is how I set "Handles" for sheets and copy data:
Code:
Dim srcSheet As Worksheet 'Handle for Source Worksheet
Dim dstSheet As Worksheet 'Handle for Destination Worksheet
'Set the handles for the Source and Destination Sheets
Set srcSheet = Sheets("Sheet2")
Set dstSheet = Sheets("Sheet1")
'Copy a cell from the Source Sheet to the Destination Sheet
srcSheet.Cells(1, c2).Copy
dstSheet.Paste (dstSheet.Cells(1, 3))
'At the end of your code, clean up all of the "Set" objects
'This is not absolutely required, but is a good habit to get into
Set srcSheet = Nothing
Set dstSheet = Nothing
Last edited by Webtest; Mar 28th, 2006 at 08:38 AM.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Mar 28th, 2006, 09:40 PM
#8
Thread Starter
New Member
Re: need help
tanx man,,,..
just one question.. how to extract row and column from range..
for example range("a2") i want to get the index number. and represent them in variable so that i can manipulate
-
Mar 29th, 2006, 12:47 PM
#9
Frenzied Member
Re: need help
"Row" returns the first Row Index in a range
"Rows.Count" returns the number of Rows in a range
"Column" returns the first Column Index in a range
"Columns.Count" returns the number of columns in a range
Code:
aRow = Range("C5:F17").Row
aCol = Range("C5:F17").Column
MsgBox aRow & Chr(10) & aCol
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|