Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PAG PAG is offline
external usenet poster
 
Posts: 14
Default Find column and then insert column

Hi,

I am new to creating macros in Excel.

Can someone please help me add to a macro I currently use.

All I want to do is search an excel workbook for a particular
column(Original Notional) and have the macro add that column if it isn't
alreay there. There normally is the following columns of X-Date, Payment
Date, Fund, Sub-Portfolio, Cusip, Broker, Security Name, Notional Amt , and
Total Payment. Sometimes the workbook has the Original Notional and sometimes
it doesn't. If the Original Notional column is there it would before the
Total Payment column.

Can anyone please help me?


Thank You

Peter
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Find column and then insert column

The easiest method is to use find

with workbooks("book1.xls").sheets("Sheet1")
set c = Rows("1:1").find(what:="Original",lookin:=xlValues )
if not c is nothing then
'enter code if found
else
set c = Rows("1:1").find(what:="total",lookin:=xlValues)
if not c is nothing then
c.entirecolumn.insert
c.value = "Original"
end if
end if
end with


"PAG" wrote:

Hi,

I am new to creating macros in Excel.

Can someone please help me add to a macro I currently use.

All I want to do is search an excel workbook for a particular
column(Original Notional) and have the macro add that column if it isn't
alreay there. There normally is the following columns of X-Date, Payment
Date, Fund, Sub-Portfolio, Cusip, Broker, Security Name, Notional Amt , and
Total Payment. Sometimes the workbook has the Original Notional and sometimes
it doesn't. If the Original Notional column is there it would before the
Total Payment column.

Can anyone please help me?


Thank You

Peter

  #3   Report Post  
Posted to microsoft.public.excel.programming
PAG PAG is offline
external usenet poster
 
Posts: 14
Default Find column and then insert column

Hi Joel,

I tried the below but it inserts a new column and then renames the Total
Payment column to Original Notional.

With ActiveWorkbook
Set c = Rows("1:1").Find(what:="Original Notional", LookIn:=xlValues)
If Not c Is Nothing Then
'enter code if found
Else
Set c = Rows("1:1").Find(what:="Total Payment", LookIn:=xlValues)
If Not c Is Nothing Then
c.EntireColumn.Insert
c.Value = "Original Notional"
End If
End If
End With

"PAG" wrote:

Hi,

I am new to creating macros in Excel.

Can someone please help me add to a macro I currently use.

All I want to do is search an excel workbook for a particular
column(Original Notional) and have the macro add that column if it isn't
alreay there. There normally is the following columns of X-Date, Payment
Date, Fund, Sub-Portfolio, Cusip, Broker, Security Name, Notional Amt , and
Total Payment. Sometimes the workbook has the Original Notional and sometimes
it doesn't. If the Original Notional column is there it would before the
Total Payment column.

Can anyone please help me?


Thank You

Peter

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Find column and then insert column

I wasn't sure after the column is added which column C would refer to.

from
c.Value = "Original Notional"
to
c.offset(0,-1).Value = "Original Notional"


"PAG" wrote:

Hi Joel,

I tried the below but it inserts a new column and then renames the Total
Payment column to Original Notional.

With ActiveWorkbook
Set c = Rows("1:1").Find(what:="Original Notional", LookIn:=xlValues)
If Not c Is Nothing Then
'enter code if found
Else
Set c = Rows("1:1").Find(what:="Total Payment", LookIn:=xlValues)
If Not c Is Nothing Then
c.EntireColumn.Insert
c.Value = "Original Notional"
End If
End If
End With

"PAG" wrote:

Hi,

I am new to creating macros in Excel.

Can someone please help me add to a macro I currently use.

All I want to do is search an excel workbook for a particular
column(Original Notional) and have the macro add that column if it isn't
alreay there. There normally is the following columns of X-Date, Payment
Date, Fund, Sub-Portfolio, Cusip, Broker, Security Name, Notional Amt , and
Total Payment. Sometimes the workbook has the Original Notional and sometimes
it doesn't. If the Original Notional column is there it would before the
Total Payment column.

Can anyone please help me?


Thank You

Peter

  #5   Report Post  
Posted to microsoft.public.excel.programming
PAG PAG is offline
external usenet poster
 
Posts: 14
Default Find column and then insert column

That worked Joel - Thank you so much

"Joel" wrote:

I wasn't sure after the column is added which column C would refer to.

from
c.Value = "Original Notional"
to
c.offset(0,-1).Value = "Original Notional"


"PAG" wrote:

Hi Joel,

I tried the below but it inserts a new column and then renames the Total
Payment column to Original Notional.

With ActiveWorkbook
Set c = Rows("1:1").Find(what:="Original Notional", LookIn:=xlValues)
If Not c Is Nothing Then
'enter code if found
Else
Set c = Rows("1:1").Find(what:="Total Payment", LookIn:=xlValues)
If Not c Is Nothing Then
c.EntireColumn.Insert
c.Value = "Original Notional"
End If
End If
End With

"PAG" wrote:

Hi,

I am new to creating macros in Excel.

Can someone please help me add to a macro I currently use.

All I want to do is search an excel workbook for a particular
column(Original Notional) and have the macro add that column if it isn't
alreay there. There normally is the following columns of X-Date, Payment
Date, Fund, Sub-Portfolio, Cusip, Broker, Security Name, Notional Amt , and
Total Payment. Sometimes the workbook has the Original Notional and sometimes
it doesn't. If the Original Notional column is there it would before the
Total Payment column.

Can anyone please help me?


Thank You

Peter



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
Macro - Find Next Change In A Column; then insert row masterbaker Excel Programming 5 July 9th 07 05:48 PM
Find emty cell in column and insert value Mikus Excel Programming 3 August 17th 05 01:47 PM
Macro - Insert&Label Column, if the labeled column doesn't exist Jeff[_43_] Excel Programming 1 December 15th 04 09:33 PM
Need Macro to Find Column Heading -- if none, then insert new column Jeff[_43_] Excel Programming 0 December 15th 04 07:08 AM
find row value, insert column gaba Excel Programming 0 October 18th 04 06:59 PM


All times are GMT +1. The time now is 06:28 AM.

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

About Us

"It's about Microsoft Excel"