ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   writing a vba code for a simple function (https://www.excelbanter.com/excel-programming/436311-writing-vba-code-simple-function.html)

niloy parvaz

writing a vba code for a simple function
 
Hi

I have just started using VBA from today and I am slowly getting the grasp of it. For the time being I am supposed to write a code to execute a certain function. Let me break down the scenario. I have a table with some names (which is linked to a different worksheet). if instead of the names, an error message comes up, I want to retrieve all the rows with the errors and transfer these messages to a different worksheet showing the errors.

I was thinking about maybe using strings and conditional commands but since I just started using VBA I cant quite figure out the picture as to how to go about writing the code. Could you please help me out? I would appreciate it

EggHeadCafe - Software Developer Portal of Choice
Silverlight 3 Bing API: A Related Links Widget
http://www.eggheadcafe.com/tutorials...-bing-api.aspx

Bernie Deitrick

writing a vba code for a simple function
 
In the errors are in column A of the activesheet, and you want to transfer the errors to a sheet
named Errors, then you could use


Sub Macro1()
Dim myC As Range
Dim myR As Range
Dim myS As Worksheet
Dim myD As Worksheet

Set myS = ActiveSheet
Set myD = Worksheets("Errors")

myD.Activate

Set myR = Intersect(myS.Range("A:A"), myS.UsedRange)
For Each myC In myR.SpecialCells(xlCellTypeFormulas, 16)
myC.EntireRow.Cut
myD.Cells(Rows.Count, 1).End(xlUp)(2).EntireRow.Select
myD.Paste
Next myC

myR.SpecialCells(xlCellTypeBlanks).EntireRow.Delet e
End Sub

HTH,
Bernie
MS Excel MVP


<niloy parvaz wrote in message ...
Hi

I have just started using VBA from today and I am slowly getting the grasp of it. For the time
being I am supposed to write a code to execute a certain function. Let me break down the scenario.
I have a table with some names (which is linked to a different worksheet). if instead of the
names, an error message comes up, I want to retrieve all the rows with the errors and transfer
these messages to a different worksheet showing the errors.

I was thinking about maybe using strings and conditional commands but since I just started using
VBA I cant quite figure out the picture as to how to go about writing the code. Could you please
help me out? I would appreciate it

EggHeadCafe - Software Developer Portal of Choice
Silverlight 3 Bing API: A Related Links Widget
http://www.eggheadcafe.com/tutorials...-bing-api.aspx




joel

writing a vba code for a simple function
 
Try something like this


Set MyErrors = Sheets(1).Cells.SpecialCells( _
xlCellTypeFormulas, xlErrors).EntireRow
MyErrors.Copy destination:=Sheets(2).Cells

"niloy parvaz" wrote:

Hi

I have just started using VBA from today and I am slowly getting the grasp of it. For the time being I am supposed to write a code to execute a certain function. Let me break down the scenario. I have a table with some names (which is linked to a different worksheet). if instead of the names, an error message comes up, I want to retrieve all the rows with the errors and transfer these messages to a different worksheet showing the errors.

I was thinking about maybe using strings and conditional commands but since I just started using VBA I cant quite figure out the picture as to how to go about writing the code. Could you please help me out? I would appreciate it

EggHeadCafe - Software Developer Portal of Choice
Silverlight 3 Bing API: A Related Links Widget
http://www.eggheadcafe.com/tutorials...-bing-api.aspx
.



All times are GMT +1. The time now is 01:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com