循环excel做判断java_Excel-VBA循环ifs

该博客探讨如何优化Excel VBA宏,以高效地处理大量数据。作者试图通过Java循环实现IFS判断,当I列值等于1且G列值小于30或H列值小于0.03时,将I列值设为0。当前有两个宏分别处理这两个条件,但寻求更简洁的解决方案。博客内容包括两个VBA子程序,分别检查G列和H列的条件。
摘要由CSDN通过智能技术生成

我已经编写了2个宏来完成这项任务,但我正在努力巩固并提高效率 .

如果列 I 中有值= 1(它将为空或= 1),请查看 G 列

如果 G 列中的值<30或者如果 H 列中的值<0.03那么将第I列中的值覆盖为= "0" ...(如果不是,则不要更改 I 列中的值并继续检查下一个)

范围是 I9:I45000 , G9:G45000 和 H9:H45000 .

我认为有一个简单的解决方案,但几个小时后,我没有受过教育的自己找不到它 .

Module1:

Dim rngCell As Range, _

rngDataRange As Range

Set rngDataRange = Range("G9:G45000")

For Each rngCell In rngDataRange

With rngCell

If .Value < 30 Then

.Offset(0, 2).Value = "0" 'A[rngCell] to C[rngCell]

End If

End With

Next rngCell

End Sub

Module2:

Sub Macro1()

Dim rngCell As Range, _

rngDataRange As Range

Set rngDataRange = Range("H9:H45000")

For Each rngCell In rngDataRange

With rngCell

If .Value < 0.03 Then

.Offset(0, 1).Value = "0" 'A[rngCell] to C[rngCell]

End If

End With

Next rngCell

End Sub

This is the macro I run first.... It puts values in some of the cells in column I (where column C has values less than 1575):

Sub Macro1()Dim rngCell As Range,_ rngDataRange As Range

Set rngdataRange = Range (C9:C45000)

For Each rngCell In rngDataRange

With rngCell

If .Value < 1575 Then

.Offset (0,6).Value="1"

End If

End With

Next rngCell

结束子

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是修改后的代码,将基因树文件的名称与对比结果对应起来: ```R library(ape) species_tree <- read.tree("species_tree.treefile") # 定义一个函数来比较树拓扑结构差异 compare_trees <- function(gene_tree_file, species_tree) { gene_tree <- read.tree(gene_tree_file) diff_count <- comparePhylo(gene_tree, species_tree, force.rooted = TRUE) return(diff_count) } # 定义一个函数来批量比较基因树和物种树的差异 batch_compare_trees <- function(gene_tree_folder, species_tree) { gene_tree_files <- list.files(path = gene_tree_folder, pattern = ".treefile", full.names = TRUE) diff_counts <- numeric(length(gene_tree_files)) gene_tree_names <- character(length(gene_tree_files)) # 添加一个空的字符向量,用于存储基因树的名称 for (i in seq_along(gene_tree_files)) { gene_tree_file <- gene_tree_files[i] gene_tree_names[i] <- basename(gene_tree_file) # 获取基因树文件的名称,并存储到对应位置 diff_counts[i] <- compare_trees(gene_tree_file, species_tree) } colnames(diff_counts) <- gene_tree_names # 将基因树文件的名称设置为diff_counts的列名 return(diff_counts) } # 设置基因树文件夹路径 gene_tree_folder <- "/ifs1/User/dengwei/NTF_data/rotted_gene_tree" # 替换为你的基因树文件夹路径 # 执行批量比较 diff_counts <- batch_compare_trees(gene_tree_folder, species_tree) ``` 在修改后的代码中,我添加了一个新的字符向量`gene_tree_names`来存储基因树文件的名称。在循环中,我使用`basename()`函数获取基因树文件的名称,并将其存储到`gene_tree_names`的对应位置。然后,我使用`colnames()`函数将基因树文件的名称设置为`diff_counts`的列名,以实现基因树名称与对比结果的对应关系。 请注意,您需要将`gene_tree_folder`替换为您实际的基因树文件夹路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值