Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default inputing data

hi how can i modify this code so that the data is entered in the next empty
cell in
column a

Sub ImportDataFile()
Dim myFName As Variant
Dim myWkSht As Worksheet

Set myWkSht = ActiveSheet

ChDir "C:\mydata"
myFName = Application.GetOpenFilename(, , "Select the Data File")

If myFName = False Then
MsgBox "You pressed Cancel"
Exit Sub
Else
Workbooks.OpenText Filename:=myFName, _
StartRow:=1, DataType:=xlDelimited, Comma:=True
End If

Range("A:D").Copy _
myWkSht.Range("A:D")
ActiveWorkbook.Close False
'
End Sub

thanks for the help guys

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default inputing data

Untested...

Option Explicit
Sub ImportDataFile()

Dim myFName As Variant
Dim myWkSht As Worksheet
Dim DestCell As Range

ChDir "C:\mydata"
myFName = Application.GetOpenFilename(, , "Select the Data File")

If myFName = False Then
MsgBox "You pressed Cancel"
Exit Sub
End If

Set myWkSht = ActiveSheet

With myWkSht
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

Workbooks.OpenText Filename:=myFName, _
StartRow:=1, DataType:=xlDelimited, Comma:=True

ActiveSheet.Range("a1").CurrentRegion.Copy _
Destination:=DestCell

ActiveWorkbook.Close savechanges:=False

End Sub

ashw1984 wrote:

hi how can i modify this code so that the data is entered in the next empty
cell in
column a

Sub ImportDataFile()
Dim myFName As Variant
Dim myWkSht As Worksheet

Set myWkSht = ActiveSheet

ChDir "C:\mydata"
myFName = Application.GetOpenFilename(, , "Select the Data File")

If myFName = False Then
MsgBox "You pressed Cancel"
Exit Sub
Else
Workbooks.OpenText Filename:=myFName, _
StartRow:=1, DataType:=xlDelimited, Comma:=True
End If

Range("A:D").Copy _
myWkSht.Range("A:D")
ActiveWorkbook.Close False
'
End Sub

thanks for the help guys


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default inputing data


You can select cell A1 in the activeworksheet and then use the code below to
move to the next blank cell, if A1 is not empty

If ActiveCell.Value < "" Then
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
End If

--
Kevin Backmann


"ashw1984" wrote:

hi how can i modify this code so that the data is entered in the next empty
cell in
column a

Sub ImportDataFile()
Dim myFName As Variant
Dim myWkSht As Worksheet

Set myWkSht = ActiveSheet

ChDir "C:\mydata"
myFName = Application.GetOpenFilename(, , "Select the Data File")

If myFName = False Then
MsgBox "You pressed Cancel"
Exit Sub
Else
Workbooks.OpenText Filename:=myFName, _
StartRow:=1, DataType:=xlDelimited, Comma:=True
End If

Range("A:D").Copy _
myWkSht.Range("A:D")
ActiveWorkbook.Close False
'
End Sub

thanks for the help guys

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
inputing data using vba [email protected] Excel Programming 0 January 10th 06 04:15 AM
inputing data using vba [email protected] Excel Discussion (Misc queries) 0 January 10th 06 04:09 AM
inputing data [email protected] Excel Discussion (Misc queries) 0 December 28th 05 02:01 PM
Inputing Data Dick Kusleika Excel Programming 0 August 14th 03 09:13 PM
Inputing Data DLS[_3_] Excel Programming 5 August 10th 03 02:16 AM


All times are GMT +1. The time now is 04:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"